#include "stdafx.h"
#include "../client/DCPlusPlus.h"
#include "Resource.h"

#include "FavHubDisableRaw.h"
#include "LineDlg.h"
#include "../client/Util.h"

#define ATTACH(id, var) var.Attach(GetDlgItem(id))

LRESULT FavHubDisableRawDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {

	ATTACH(IDC_DISABLE_RAW_MYINFO, myinfo);
	ATTACH(IDC_DISABLE_RAW_CLIENT, client);
	ATTACH(IDC_DISABLE_RAW_FAKE_SHARE, filelist);
	ATTACH(IDC_DISABLE_RAW_GPL_BREAKERS, adls);
	ATTACH(IDC_DISABLE_RAW_FAKER, multihub);
	ATTACH(IDC_DISABLE_RAW_FILELIST, faker);
	ATTACH(IDC_DISABLE_RAW_ADLS, badConnection);
	ATTACH(IDC_DISABLE_RAW_MULTIHUB, badIsp);
	ATTACH(IDC_DISABLE_RAW_CONNECTION_TROUBLE, flooder);
	ATTACH(IDC_DISABLE_RAW_BAD_ISP, fakeShare);
	ATTACH(IDC_DISABLE_RAW_POSSIBLE_FLOODER, buggyClient);

	::CheckDlgButton(*this, IDC_DISABLE_RAW_MYINFO,					Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 0)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_CLIENT,					Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 1)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_FILELIST,				Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 2)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_ADLS,					Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 3)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_MULTIHUB,				Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 4)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_FAKER,					Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 5)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_CONNECTION_TROUBLE,		Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 6)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_BAD_ISP,				Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 7)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_POSSIBLE_FLOODER,		Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 8)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_FAKE_SHARE,				Util::toBool(Util::getTokenAt(disableRawsDlg, ';', 9)) ? BST_CHECKED : BST_UNCHECKED);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_GPL_BREAKERS,			BST_UNCHECKED);

	CenterWindow(GetParent());
	return FALSE;
}

LRESULT FavHubDisableRawDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	if(wID == IDOK) {
		CButton btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_MYINFO);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 0, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 0, "0");
		btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_CLIENT);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 1, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 1, "0");
		btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_FILELIST);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 2, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 2, "0");
		btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_ADLS);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 3, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 3, "0");
		btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_MULTIHUB);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 4, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 4, "0");
		btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_FAKER);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 5, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 5, "0");
		btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_CONNECTION_TROUBLE);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 6, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 6, "0");
		btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_BAD_ISP);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 7, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 7, "0");
		btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_POSSIBLE_FLOODER);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 8, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 8, "0");
		btn = ::GetDlgItem(m_hWnd, IDC_DISABLE_RAW_FAKE_SHARE);
		btn.GetCheck() ? disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 9, "1") : disableRawsDlg = Util::replaceTokenAt(disableRawsDlg, ';', 9, "0");
	}
	EndDialog(wID);
	return 0;
}

LRESULT FavHubDisableRawDlg::OnBnClickedDisableRawGplBreakers(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	MessageBox(_T("Ooops, try again."), _T("Bugger"), MB_ICONSTOP | MB_OK);
	::CheckDlgButton(*this, IDC_DISABLE_RAW_GPL_BREAKERS, BST_UNCHECKED);
	return 0;
}
